<html>
    <head>
        <title>Itowns - Globe + vector-tiles</title>

        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="css/example.css">
        <link rel="stylesheet" type="text/css" href="css/noto.css">
        <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
    </head>
    <body>
        <div id="viewerDiv"></div>
        <div id="debug" width="400" height="300"></div>
        <script src="js/GUI/GuiTools.js"></script>
        <script src="../dist/itowns.js"></script>
        <script src="js/GUI/LoadingScreen.js"></script>
        <script src="../dist/debug.js"></script>
        <script>
            // # Simple Globe viewer + a vector tile layer

            // Define initial camera position
            var placement = {
                coord: new itowns.Coordinates('EPSG:4326', 2.475, 48.807),
                range: 12000000,
            }
            var promises = [];

            // `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
            var viewerDiv = document.getElementById('viewerDiv');

            // Instanciate iTowns GlobeView*
            var view = new itowns.GlobeView(viewerDiv, placement);

            // define pole texture
            view.tileLayer.noTextureColor = new itowns.THREE.Color(0x95c1e1);

            view.getLayerById('atmosphere').visible = false;
            view.getLayerById('atmosphere').fog.enable = false;

            setupLoadingScreen(viewerDiv, view);

            promises.push(itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
                config.source = new itowns.WMTSSource(config.source);
                var layer = new itowns.ColorLayer('Ortho', config);
                return view.addLayer(layer);
            }));

            // Define a VectorTilesSource to load Vector Tiles data from the geoportail
            var mvtSource = new itowns.VectorTilesSource({
                style: 'https://wxs.ign.fr/essentiels/static/vectorTiles/styles/PLAN.IGN/standard.json',
                // We don't display mountains related data to ease visualisation
                filter: (layer) => !layer['source-layer'].includes('oro_') && !layer['source-layer'].includes('parcellaire'),
            });

            var mvtLayer = new itowns.ColorLayer('MVT', {
                source: mvtSource,
                effect_type: itowns.colorLayerEffects.removeLightColor,
                effect_parameter: 2.5,
                addLabelLayer: true,
            });

            view.addLayer(mvtLayer);

            var menuGlobe = new GuiTools('menuDiv', view, 300);
            // Listen for globe full initialisation event
            view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
                Promise.all(promises).then(function () {
                    menuGlobe.addImageryLayersGUI(view.getLayers(function (l) { return l.isColorLayer; }));
                    itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
                }).catch(console.error);
            });

            debug.createTileDebugUI(menuGlobe.gui, view);
        </script>
    </body>
</html>
